import random
from .ttable import ttable

#
# stat class
#
class Stat(object):
	def __init__(self, *args, **kw):
		object.__init__(self)
#
#		store the namem of the stat and the name as found
#		in the xml files for reference
#
		self.name = kw["name"]
		self.xml_name = ttable[self.name]
#
#		value defults to zero.
#		random range generation is off by default
#
		self.value = 0.0
		self.random = False
		self.lo_val = 0
		self.hi_val = 0
#
#	casting functions - mostly we'll use string or float
#	we'll get strings back from XML, but they'll get
#	stored back as numerics
#
#	actually, I probably won't need these after all...
#
	def sval(self):
		return str(self.value)
	def ival(self):
		return int(self.value)
	def fval(self):
		return float(self.value)
	def randomise(self):
		if not self.random:
			return self.value
		self.value = random.randint(
			int(self.lo_val),
			int(self.hi_val) + 1
		)
		return self.value

